import bisect
from collections import Counter
import matplotlib.pyplot as plt
import numpy as np

init = 1602787034.862464
data = []
gdata = []
stpes = [init]
for line in open('fpm1-down.log'):
    data.append(float(line.split(' - ')[1]) - init)

x = data
n = np.arange(1, len(x) + 1) / np.float(len(x))
Xs = np.sort(x)

# plt.figure()
fig, ax = plt.subplots(figsize=(6, 4))
ax.step(Xs, n)

ax.grid(True)
ax.legend(loc='right')
ax.set_title('CDF ospf link down')
ax.set_xlabel('Time(s)')
plt.savefig('%s.png' % "down-cdf")
plt.show()
#
# next = init
# while True:
#     next = stpes[len(stpes) - 1] + 1
#     stpes.append(next)
#     if next > data[len(data) - 1]:
#         break
#
# c = Counter(stpes[bisect.bisect_left(stpes, item)] for item in data)
# cc = collections.OrderedDict(sorted(c.items()))
# plt.plot(cc.keys(), cc.values())
# plt.show()
